//
//  LJMRecommendCollectionViewCell.m
//  wind
//
//  Created by 李金明 on 16/1/11.
//  Copyright © 2016年 李金明. All rights reserved.
//

#import "LJMRecommendCollectionViewCell.h"
#import "SuggestPageTableViewCell.h"
#import "LJMListen_Model.h"

@interface LJMRecommendCollectionViewCell ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain) UITableView *tableV;

@end

@implementation LJMRecommendCollectionViewCell

- (void)setDataArr:(NSMutableArray *)dataArr
{
    if (_dataArr != dataArr) {
        [_dataArr release];
        _dataArr = [dataArr retain];
    }
    [self.tableV reloadData];
}

- (void)dealloc
{
    self.delegate = nil;
    [_tableV release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatView];
    }
    return self;
}
- (void)creatView
{
//    self.backgroundColor = [UIColor yellowColor];
    
    self.tableV = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    [self addSubview:self.tableV];
    [_tableV release];
    
}

// 选中行放歌
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%ld", indexPath.row);
    NSLog(@"%@", self.dataArr);
    
    
    
    
    
    
    [self.delegate playWithAuditionListArr:self.dataArr index:indexPath.row];
}

// 行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.bounds.size.height * 3 / 4;
}

// 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"%@", self.dataArr);
    return self.dataArr.count;
}

// tableviewCell出现方式
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    
    cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1);
    [UIView animateWithDuration:0.5 animations:^{
        cell.layer.transform = CATransform3DMakeScale(1, 1, 1);
    }];
    
}

// cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellStr = @"suggestpageCell";
    SuggestPageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (cell == nil) {
        cell = [[[SuggestPageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr] autorelease];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    LJMListen_Model *model = [self.dataArr objectAtIndex:indexPath.row];
    if (![model.singerName isKindOfClass:[NSNull class]]) {
        cell.singerName.text = model.singerName;
    }
    
    if (![model.name isKindOfClass:[NSNull class]]) {
        cell.songName.text = model.name;
    }
    
    if (![model.picUrl isKindOfClass:[NSNull class]]){
        [cell.imageV sd_setImageWithURL:[NSURL URLWithString:model.picUrl] placeholderImage:[UIImage imageNamed:@"clamdown"]];
    }
    return cell;
}

@end
